package com.unei.mq;

import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;

import java.net.URI;

/**
 * Created by sunlei on 2015/8/6.
 */
public class Broker {
    public static String uri ="tcp://localhost:61616?trace=true";
    public static String nioUri="nio://localhost:61617?trace=true";

    public static void main(String[] args) throws Exception {
        startLazy();
        Thread.sleep(100000000000L);
    }

    public static void start() throws Exception {
        BrokerService brokerService=new BrokerService();
        brokerService.addConnector(uri);
        brokerService.start();
    }

    public static void startLazy() throws Exception {
        BrokerService brokerService=new BrokerService();
        brokerService.setUseJmx(false);
//        brokerService.setPersistenceFactory(new KahaDBPersistenceAdapter());
//        TransportConnector connector=new TransportConnector();
//        connector.setUri(new URI(uri));
//        brokerService.addConnector(connector);

        TransportConnector nioConnector=new TransportConnector();
        nioConnector.setUri(new URI(nioUri));
        brokerService.addConnector(nioConnector);

        brokerService.start();
    }
}
